﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace HUNGVM.UI
{
    public partial class frmsinhvien1 : Form
    {
        public frmsinhvien1()
        {
            InitializeComponent();
        }

        private void btnHienThiThongTin_Click(object sender, EventArgs e)
        {
        
            SqlConnection conn = new SqlConnection(@"Data Source=HUNGHIHI\HUNGVM;Initial Catalog=SINHVIEN;Integrated Security=True");

          
            SqlCommand cmd = new SqlCommand("SELECT * FROM SinhVien",conn);

           
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);

            dataGridView1.DataSource = dt;

            //

           
        }

        private void btnKiemTraKetNoi_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=HUNGHIHI\HUNGVM;Initial Catalog=SINHVIEN;Integrated Security=True");
            try
            {
                conn.Open();
                MessageBox.Show(" Kết nối thành công");
                conn.Close();
            }
            catch (SqlException ex)
            {

                MessageBox.Show(" kết nối cơ sở dữ liệu thất bại");
            }
            finally
            {
                conn.Close();
            }

        }

        private void brnThem_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(@"Data Source=HUNGHIHI\HUNGVM;Initial Catalog=SINHVIEN;Integrated Security=True");
             
       
            

            string sql = String.Format("INSERT INTO SinhVien(TENSV, MASV) VALUES ('{0}', '{1}')", txtMaSinhVieb.Text, txtTenSinhVien.Text);
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();

            btnHienThiThongTin.PerformClick();



        }
    }
}
